<template>
  <div class="p-2">

    <div class="mb-[10px]">
      <el-card>
        <el-form
          ref="queryFormRef"
          :model="queryParams"
          :inline="true"
          label-width="auto"
        >
          <el-form-item
            label="服务商名称"
            prop="gsmc"
          >
            <el-input
              v-model="queryParams.gsmc"
              placeholder="请输入服务商名称"
              clearable
              style="width: 240px"
              @keyup.enter="handleQuery"
            />
          </el-form-item>
          <el-form-item
            label="服务商编码"
            prop="no"
          >
            <el-input
              v-model="queryParams.no"
              placeholder="请输入服务商编码"
              clearable
              style="width: 240px"
              @keyup.enter="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              @click="handleQuery"
              icon="Search"
            >查询</el-button>
            <el-button
              @click="resetQuery"
              icon="Refresh"
            >重置</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
    <el-card>
      <template #header   >
        <el-row :gutter="10" v-hasPermi="['payment:syd:add']" >
          <el-col :span="1.5">
            <el-button
              type="primary"
              @click="addAndEditAddService('add')"
              icon="Plus"
            >新增</el-button>
          </el-col>
        </el-row>
      </template>

      <el-table
        v-loading="loading"
        :data="serviceList"
        border
      >
        <el-table-column
          label="创建时间"
          align="center"
          min-width="160"
          prop="addTime"
          sortable
        />
        <el-table-column
          label="服务商名称"
          align="left"
          min-width="240"
          prop="gsmc"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="服务商编码"
          align="left"
          min-width="160"
          prop="no"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="银行信息"
          align="left"
          min-width="240"
        >
          <template #default="scope">
            <div v-if="scope.row.kfd">开户地：{{ scope.row.kfd }}</div>
            <div v-if="scope.row.kfh">开户行：{{ scope.row.kfh }}</div>
            <div v-if="scope.row.khhNo">账号：{{ scope.row.khhNo }}</div>
          </template>
        </el-table-column>
        <el-table-column
          label="法人信息"
          align="left"
          min-width="240"
        >
          <template #default="scope">
            <div v-if="scope.row.fr">姓名：{{ scope.row.fr }}</div>
            <div v-if="scope.row.frCardid">身份证：{{ scope.row.frCardid }}</div>
            <div v-if="scope.row.frPhone">手机号：{{ scope.row.frPhone }}</div>
          </template>
        </el-table-column>
        <el-table-column
          label="联系人信息"
          align="left"
          min-width="240"
        >
          <template #default="scope">
            <div v-if="scope.row.conName">姓名：{{ scope.row.conName }}</div>
            <div v-if="scope.row.conCardid">身份证：{{ scope.row.conCardid }}</div>
            <div v-if="scope.row.conPhone">手机号：{{ scope.row.conPhone }}</div>
            <div v-if="scope.row.conEmail">邮箱：{{ scope.row.conEmail }}</div>
          </template>
        </el-table-column>
        <el-table-column
          label="虚拟户信息"
          align="left"
          min-width="240"
          prop="fwf"
        >
        </el-table-column>
        <el-table-column
          label="操作"
          fixed="right"
          align="center"
          width="310"
          class-name="small-padding fixed-width"
        >
          <template #default="scope">
            <el-tag v-hasPermi="['payment:syd:edit']" @click="addAndEditAddService('edit', scope.row)">编辑</el-tag>
            <el-tag v-hasPermi="['payment:syd:query']"  @click="addAndEditAddService('look', scope.row)">详情</el-tag>
            <el-tag v-hasPermi="['payment:syd:proMag']"  @click="jumpProductManagement(scope.row)">产品管理</el-tag>
            <el-tag v-hasPermi="['payment:syd:proJs']"  @click="settlementConfigurationFun(scope.row)">结算配置</el-tag>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
    <settlementConfiguration ref="settlementConfigurationRef"></settlementConfiguration>
  </div>
</template>

<script setup name="addService" lang="ts">
import api from '@/api/service/addService';
import { AddServiceQuery, AddServiceVO } from '@/api/service/addService/types';
import settlementConfiguration from '../components/settlementConfiguration.vue';

const router = useRouter();
const { proxy } = getCurrentInstance() as ComponentInternalInstance;

const { agent_level } = toRefs<any>(proxy?.useDict('agent_level'));

const serviceList = ref<AddServiceVO[]>();
const loading = ref(true);
const total = ref(0);
const queryFormRef = ref<ElFormInstance>();
const queryParams = ref<AddServiceQuery>({
  pageNum: 1,
  pageSize: 10,
  gsmc: '',
  no: ''
});

/** 查询代理商列表 */
const getList = async () => {
  loading.value = true;
  const res = await api.serviceList(queryParams.value);
  loading.value = false;
  serviceList.value = res.rows;
  total.value = res.total;
};

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
};
/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  queryParams.value.pageNum = 1;
  handleQuery();
};

/** 新增&修改 */
const addAndEditAddService = (type: string, row: any = '') => {
  router.push(type == 'look' ? 'serviceDetail?id=' + row.id : type == 'edit' ? 'serviceEdit?id=' + row.id : 'serviceAdd');
};
/** 产品管理 */
const jumpProductManagement = (row: any = '') => {
  router.push('productManagement?sydNo='+row.no+"&sydId="+row.id);
};

/** 结算配置 */
const settlementConfigurationRef = ref<any>();
const settlementConfigurationFun = (row: AddServiceVO) => {
  settlementConfigurationRef.value.settlementConfigurationVisibleFun(row);
};

onMounted(() => {
  getList(); // 初始化列表数据
});
</script>

<style lang="scss" scoped></style>
